package com.shengwei.truck.driver.vm;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.shengwei.truck.driver.view.ui.app.MyApplication;
import com.shengwei.truck.driver.bean.Result;
import com.shengwei.truck.driver.bean.task.JsonTaskDetailData;
import com.shengwei.truck.driver.model.DataSource;
import com.shengwei.truck.driver.model.Repository;

/**
 * 登录页面的VM层，调用M层去获取数据，同时更改liveData的数据，从而View层就能观察到LiveData数据的
 * 变化，最后更新UI。
 */
public class TaskDetailViewModel extends ViewModel {
    String TAG = "TaskDetailViewModel";
    //任务详情
    private MutableLiveData<Result<JsonTaskDetailData>> mTaskDetailLiveData = new MutableLiveData<>();
    private MutableLiveData<Result<String>> mRecvTaskLiveData = new MutableLiveData<>();
    private MutableLiveData<Result<String>> mCancelTaskLiveData = new MutableLiveData<>();
    private Repository mRepository; //M层引用
    private MyApplication mApp;


    /**
     * 构造函数
     * @param Repository: M层对象实例
     */
    public TaskDetailViewModel(Repository Repository) {
        this.mRepository = Repository;
    }

    public TaskDetailViewModel() {
        mRepository = Repository.getInstance(DataSource.getSingleInstance());
    }

    public MutableLiveData<Result<JsonTaskDetailData>> getTaskDetailLiveData() {
        return mTaskDetailLiveData;
    }
    public MutableLiveData<Result<String>> getCancelTaskLiveData() {
        return mCancelTaskLiveData;
    }

    public MutableLiveData<Result<String>> getRecvTaskLiveData() {
        return mRecvTaskLiveData;
    }

    /**
     * VM层调用M层（Repository+DataSource）
     * @param taskId : 任务ID
     * @return
     */
    public void getTaskDetail(String taskId) {
          mRepository.getTaskDetail(taskId,mTaskDetailLiveData);
    }

    /**
     * 接受任务
     * @param taskId: 任务ID
     * @param taskStatus：任务状态
     */
    public void recvTaskDetail(String taskId,int taskStatus) {
        mRepository.recvTaskDetail(taskId,taskStatus,mRecvTaskLiveData);
    }



    /**
     * 撤销任务
     * @param taskId: 任务ID
     */
    public void cancelTask(String taskId) {
        mRepository.cancelTask(taskId,mCancelTaskLiveData);
    }





}